﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Services;
using Domain;
using System.Data.Linq;

namespace Concrete {
    public class SqlRepository : IRepository {

        private Table<Product> productsTable;
        public SqlRepository(string connectionString) {

            productsTable = (new DataContext(connectionString)).GetTable<Product>();

        }

        public Product GetById(int Id) {
            return productsTable.Where(x => x.ID == Id).FirstOrDefault();
        }

        public List<Product> GetAll() {
            return productsTable.ToList();
        }

        public void AddNew(Product product) {
            productsTable.InsertOnSubmit(product);
            productsTable.Context.SubmitChanges();
        }
    }
}

